package com.partner.match.interceptor;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
*@Author: jzz
*@CreateTime: 2025-01-26
*@Description: 登录拦截器 sa-token
*/
@Configuration
public class LoginInterceptor implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SaInterceptor(handler->{
            SaRouter
                    .match("/user/**","/team/**") // 拦截的path列表
                    .notMatch("/user/login","/user/register","/user/recommend","/user/search/tags") // 不拦截登陆注册
                    .check(r-> StpUtil.isLogin());
        })).addPathPatterns("/**");
    }
}
